<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
<script type="text/javascript" src="__PUBLIC__/js/add-tab.js"></script>
<style type="text/css">
table{
	text-align:center;
}
.datagrid-body .datagrid-editable .datagrid-editable-input {
	border-color:#f00;
}
</style>
<script type="text/javascript">
	/*设施维修清单表格设置*/
	$(function(){
		var timestamp = new Date().getTime();
        $('#process_num').val(timestamp);
		var editorRow=undefined;  
        $('#repair').datagrid({ 
            fit:true, 
            fitColumns:true,
            iconCls:'icon-edit',
            singleSelect:true,
            title:'设施(设备)维修清单',
            rownumbers:true,
            columns:[[
            	{field:'name',title:'维修项目',width:100,editor:{type:'validatebox',options:{required:true}}},
            	{field:'count',title:'数量',width:50,editor:{type:'numberbox',options:{required:true,precision:0,min:1}}},
            	{field:'specifications',title:'规格',width:100,editor:{type:'validatebox',options:{required:true}}},
            	{field:'price',title:'单价',width:50,editor:{type:'numberbox',options:{required:true,precision:2,min:0}}},
            	{field:'use',title:'用途',width:400,editor:'text'},
             ]],
            toolbar:[{  
                text:'添加',  
                iconCls:'icon-add',  
                handler:function(){  
                	if(undefined==editorRow){
                           $('#repair').datagrid('insertRow',{index:0,row:{}});  
                           editorRow = 0;  
                           $('#repair').datagrid('selectRow', editorRow);  
                           $('#repair').datagrid('beginEdit', editorRow);  
                  
                	}
                }  
            },'-',{  
                text:'删除',  
                iconCls:'icon-remove',  
                handler:function(){  
                    var row = $('#repair').datagrid('getSelected');  
                    if (row){  
                        var index = $('#repair').datagrid('getRowIndex', row);  
                        $('#repair').datagrid('deleteRow', index);  
                        editorRow=undefined;
                    }  
                }  
            },'-',{  
                text:'保存',  
                iconCls:'icon-save',  
                handler:function(){  
                    $('#repair').datagrid('acceptChanges');  
                }  
            },'-',{  
                text:'撤消',  
                iconCls:'icon-undo',  
                handler:function(){  
                    $('#repair').datagrid('rejectChanges');  
                    editorRow=undefined;
                } 
            } 
            ],  
            onBeforeLoad:function(){  
                $(this).datagrid('rejectChanges');  
            },  
            onDblClickRow:function(rowIndex, rowData){  
                if (editorRow==undefined){  
                    $('#repair').datagrid('beginEdit', rowIndex);  
                }  
                editorRow=rowIndex;  
            },
            onAfterEdit:function(){
            	editorRow=undefined;
            }
        });

        /*提交流程/保存流程*/
    	$("#submit").click(function(){
    		var type=$(this).attr("id");
    		var employeId={$Think.session.employe_id};//通过session获得
			var des=$("#des").val();
			var check_person_id=$("#check_person_id").val();
            var msg_tip=$("#msg_tip").val();
            var msg_phone=$("#msg_phone").val();
            var process_num=$("#process_num").val();
            var tag="1";
			if(""==check_person_id){
				$.messager.alert('提示','未选择下一步任务执行人','error');
				return false;
			}
			
			var data=$('#repair').datagrid("getData");
			if((0==data.total)||(1==data.total&&$.isEmptyObject(data.rows[0]))||(2==data.total&&$.isEmptyObject(data.rows[0])&&$.isEmptyObject(data.rows[1]))){
				$.messager.alert('提示','物品购买清单为空','error');
				return false;
			}
			$.messager.progress({text:'正在提交，请稍等...'}); 
			$.post("__URL__/addRepair",{process_num:process_num,employeId:employeId,des:des,tag:tag,data:data,check_person_id:check_person_id,msg_phone:msg_phone,msg_tip:msg_tip},function(r){
				if(0==r){
					$.messager.alert('提示','提交失败','warning');
				}else{
					$.messager.progress('close'); 
					$.messager.alert('提示',r,'info');
				}
			});
    	});

		$("#keep").click(function(){
    		var type=$(this).attr("id");
    		var employeId={$Think.session.employe_id};//通过session获得
			var des=$("#des").val();
			var check_person_id=$("#check_person_id").val();
            var msg_tip=$("#msg_tip").val();
            var msg_phone=$("#msg_phone").val();
            var process_num=$("#process_num").val();
            var tag="0";
			if(""==check_person_id){
				$.messager.alert('提示','未选择下一步任务执行人','error');
				return false;
			}
			
			var data=$('#repair').datagrid("getData");
			if((0==data.total)||(1==data.total&&$.isEmptyObject(data.rows[0]))||(2==data.total&&$.isEmptyObject(data.rows[0])&&$.isEmptyObject(data.rows[1]))){
				$.messager.alert('提示','物品购买清单为空','error');
				return false;
			}
			$.messager.progress({text:'正在提交，请稍等...'}); 
			$.post("__URL__/saveRepairPost",{process_num:process_num,employeId:employeId,des:des,tag:tag,data:data,check_person_id:check_person_id,msg_phone:msg_phone,msg_tip:msg_tip},function(r){
				if(0==r){
					$.messager.alert('提示','提交失败','warning');
				}else{
					$.messager.progress('close'); 
					$.messager.alert('提示',r,'info');
				}
			});
    	});
	});
		
</script>
</head>
<body class="easyui-layout">
	<!-- 南部面板 -->
	<div data-options="region:'south',title:'详细设置'" style="height:240px;">
	<input type="hidden" name="process_num" id="process_num"/>	

<div style="padding-top: 10px;">
    <div style="text-align: center;">下一步任务设置</div>
    <div>
        <table style="width:100%;border: 1px solid #D3D3D3">
            <tbody>
                <tr>
                    <td style=" border: 1px solid #D3D3D3;width: 500px;">备注</td>
                    <td style=" border: 1px solid #D3D3D3;"><textarea style="width:99%" id="des"></textarea></td>
                </tr>
                <tr style="border: 1px solid #D3D3D3;">
                    
                    <td style=" border: 1px solid #D3D3D3;width: 500px;">
                        <span>
                            任务执行人：
                            <input value="" type="hidden">
                            <input readonly="readonly" id="check_person" class="easyui-validatebox" name="check_person" onclick="doSearch()" type="text" data-options="required:true">
                            <input type="hidden" id="check_person_id" name="check_person_id"/>
                            <span style="margin-left: 15px;">
                                <input id="msg_tip" name="msg_tip" checked="checked" type="checkbox" value="1">消息提醒
                            </span>
                            <span style="margin-left: 15px;">
                                <input id="msg_phone" name="msg_phone" type="checkbox" value="0">手机提醒
                            </span>
                        </span>
                    </td>
                    <td style=" border: 1px solid #D3D3D3;">
                        <span id="phone_num_span" style="display:none;float: left;">
                            手机号码：<input type="text" id="phone_num" name="phone_num"/>
                        </span>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('#msg_phone').change(function(){
            $('#phone_num_span').css('display','block');
            var temp =$('#msg_phone').val();
            if(temp==1){
                $('#msg_phone').val(0);
            }
            if(temp==0){
                $('#msg_phone').val(1);
            }
        })

        $('#msg_tip').change(function(){
            var temp =$('#msg_tip').val();
            if(temp==1){
                $('#msg_tip').val(0);
            }
            if(temp==0){
                $('#msg_tip').val(1);
            }
        })
    })
</script>

<div id="submitOrkeep" style="width:100%;text-align: center; margin-top:20px;">
    <a  href="#" class="easyui-linkbutton" id="submit">提交</a>
    <a  href="#" class="easyui-linkbutton" id="keep" style="margin-left:20px;">保存</a>
</div>

	</div>
	<!-- 北部面板结束 -->
	<!-- 中部面板 -->
	<div data-options="region:'center'">
		<table id="repair"></table>
	</div>
	<!-- 中部面板结束 -->
	<include file="Common:checkPerson"/>
</body>
</html>